<?php   // for user login
        include "include/top.php";
?>

<?php
//print_r( $_POST );
//print_r( $_REQUEST );
//print_r( $_GET );
//print " ";
$name = $_REQUEST['userName'];
$frist_name = $_REQUEST['userFirstName'];
$last_name = $_REQUEST['userLastName'];
$password = $_REQUEST['userPwd'];
$password2 = $_REQUEST['userPwd2'];
$user_url= $_REQUEST['userUrl'];
$email= $_REQUEST['eMail'];
//print_r($_REQUEST);



//$name = "test1";
//$password = "test1";

if ((!isset($name)) || (!isset($password))) 
{
echo "<h1> Needs name and password </h1>";
echo "<br />";
} else 
{
// connect to mysql
echo "<h1> connecting to db</h1>";
$mysql = mysqli_connect("localhost", "ospms", "ospms");
if(!$mysql) {
echo "Cannot connect to database.";
exit;
}
echo "<h1> connecting to db</h1>";
echo "<h1> connected db</h1>";
// select the appropriate database
$selected = mysqli_select_db($mysql, "OSPMS");
if(!$selected) {
echo "Cannot select database.";
exit;
}
// query the database to see if there is a record which matches
////$query = 'select count(*) from user  where user_name = '. '"john_doe"';
//echo $query;
$query = 'select count(*) from user  where user_name = '. $name ;
$result = mysqli_query($mysql, $query);
var_dump($result);
//if(!$result) {
//echo "User not found.";
//}
$row = mysqli_fetch_row($result);

$count = $row[0];
if ($count = 0) {
echo "New User";
}

$query = "INSERT INTO user (`user_name`, `first_name`, `last_name`, `email`, `website`, `password`)". 
		" VALUES ('$name','$first_name','$last_name','$email','$user_url','$password') ";


echo "$query\n";
$result = mysqli_query($mysql, $query);
$row = mysqli_fetch_row($result);

if ( $result );
{
header("Location: https://test2.transpolink.com/OSPMS/404.php");
}


//echo "var_dump($row)";
header("Location: /OSPMS/ShowUser.php");

}
?>


<?php
//      include "include/bottom.php"
?>
